package com.gxuwz.business.dao.impl;

import org.springframework.stereotype.Repository;

import com.gxuwz.business.entity.Fee;
import com.gxuwz.util.Pager;

@Repository("feeDAO")
public class FeeDAO extends BaseDaoImpl<FeeDAO> {
	
    /**
     * 添加
     * @param fee
     */
	public void save(Fee fee){
		try {
			getHibernateTemplate().save(fee);
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
	}
	
	/**
	 * 通过挂号编号查找
	 */
	public Fee findByRegId(String regId){
		String hql = "from Fee where regId = ?";
		try {
			return (Fee) getHibernateTemplate().find(hql, regId).get(0);
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
		return null;
	}
	
	/**
	 * 更新
	 */
	public void update(Fee fee){
		try {
			getHibernateTemplate().update(fee);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
	
	/**
	 * 更新治疗标准费用
	 */
	public void updateStandFee(Fee fee){
		String hql = "update Fee set standFee = ?, feeTotal = ?, feeNeed = ? where regId = ?";
		try {
			getHibernateTemplate().bulkUpdate(hql, fee.getStandFee(), fee.getFeeTotal(), fee.getFeeNeed(), fee.getRegId());
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
	}
	
	/**
	 * 分页查询
	 */
	public Pager<Fee> getByPager(Fee fee, Integer page, Integer limit){
		String hql = "from Fee where 1 = 1";
		try {
			return super.find(hql, null, null, (page-1)*limit, limit);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return null;
	}

}
